#include <stdio.h>
#include <lua.h>
#include <lualib.h>
#include <lauxlib.h>

#include "lua_timerfd.h"
#include "lua_socket.h"
#include "lua_eventfd.h"
#include "lua_epoll.h"

void openlibs(lua_State *L) {
	luaL_openlibs(L);
	luaL_requiref(L, "cauchy.timerfd", lua_lib_timerfd, 0);
	lua_pop(L, 1);
	luaL_requiref(L, "cauchy.socket", lua_lib_socket, 0);
	lua_pop(L, 1);
	luaL_requiref(L, "cauchy.eventfd", lua_lib_eventfd, 0);
	lua_pop(L, 1);
	luaL_requiref(L, "cauchy.epoll", lua_lib_epoll, 0);
	lua_pop(L, 1);
}

int main(int argc, char *argv[]) {
	lua_State *L = luaL_newstate(); 

	openlibs(L);

	int err = luaL_loadfile(L, "main.lua") || lua_pcall(L, 0, 0, 0);
	if (err) {
		fprintf(stderr, "%s\n", lua_tostring(L, -1));
		lua_pop(L, 1);
	}
	
	lua_close(L);
	return 0;
}